package models

import "github.com/jinzhu/gorm"

type Notes struct {
	gorm.Model
	Key     string `gorm:"unique;not null"`
	UserID  int
	User    User
	Title   string `gorm:"varchar(200)"`
	Summary string `gorm:"varchar(800)"`
	Content string `gorm:"type:text"`
	Visit   int    `gorm:"default:0"`
	Praise  int    `gorm:"default:0"`
}

func QueryNoteByKey(key string) (notes Notes, err error) {
	return notes, db.Where("key = ?", key).Take(&notes).Error
}

func SaveNotes(notes *Notes) error {
	return db.Save(notes).Error
}
